package com.njupt.Array;

/**
 * @Author: wujiaming
 * @CreateTime: 2025/3/7 10:47
 * @Description: 560. 和为 K 的子数组
 * @Version: 1.0
 */


public class SubarraySum_560 {

    /**
     * 暴力法
     * @param nums
     * @param k
     * @return
     */
    public int subarraySum(int[] nums, int k) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int sum = 0;
            for (int j = i; j < nums.length; j++) {
                sum += nums[j];
                if(sum == k){
                    count++;
                }
            }
        }
        return count;
    }



    public static void main(String[] args) {
        int[] nums = {1,2,3};
        SubarraySum_560 test = new SubarraySum_560();
        System.out.println(test.subarraySum(nums, 3));
    }
}
